package com.chee.plant.hibernate.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import com.chee.plant.hibernate.object.Plant;
import com.chee.plant.server.HibernateSessionFactory;

/**
 * 
 * @author xue cb
 * 
 */
public class PlantDAO extends BaseHibernateDAO {

	/**
	 * 根据植物Id查询植物
	 * 
	 * @param id
	 *            植物Id
	 * @return 特定的植物
	 */
	public Plant getPlantById(Integer id) {
		Session session = HibernateSessionFactory.getSession();
		String hql = "select plant from Plant as plant where plant.Id=:id";
		Query query = session.createQuery(hql);
		query.setInteger("id", id);
		return (Plant) query.uniqueResult();

	}

	/**
	 * 主方法，用于测试
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// 1 测试 getPlantById(Integer id)
		Plant plant = new PlantDAO().getPlantById(1);
		System.out.println(plant.getRipeTime());

	}

}
